package observer;

public class Client {
    public static void main(String[] args) {

        //目标对象
        Subject subject = new ConcreteSubject();

        //创建2个观察者
        Observer observerA = new ObserverA();
        Observer observerB = new ObserverB();

        //将2个观察者注册到订阅队伍
        System.out.println("注册观察者A和观察者B");
        subject.addObserver(observerA);
        subject.addObserver(observerB);

        //通知所有观察者
        System.out.println("通知所有观察者");
        subject.notifyAllObservers();

        System.out.println("---------------------");
        //移除观察者A
        System.out.println("移除观察者A");
        subject.removeObserver(observerA);
        //通知所有观察者
        System.out.println("通知所有观察者");
        subject.notifyAllObservers();
    }
}
